*constructing endogenous tech measures

 *need to crosswalk from the soc codes to census codes
 
 use "$dir/data/interim/mean_tech_by_cz_census_2016_collapsed.dta", clear 
 


foreach year in 2007 2010 2011 2012 2013 2014 2015 2016 {

merge m:1 czone year census2010 using   "$dir/data/interim/oas_cz_weights_`year'.dta", update
drop if _merge == 2
rename _merge  merge`year'

}


*constructing the contemporaneous measures:
gen contemp_mean = mean_count_tech*oas_share
gen contemp_any = mean_any_tech*oas_share
gen contemp_mean_oas = mean_count_tech*oas_share_oas
gen contemp_any_oas =mean_any_tech*oas_share_oas
gen contemp_office =mean_office*oas_share_oas
gen contemp_excel =mean_excel*oas_share_oas


*create a new measure that just uses 3 occupations: -secretaries, receptionists, office clerks: 5860 5700  5400
*create another first stage measure that uses the contemporaneous weighting
*also want to create additional measures that use weighting from further back in time, 1990 or 1980... need to use a crosswalk

gen sec=( census2010==5860 | census2010==5700 | census2010==5400)

gen contemp_mean_sec = mean_count_tech*oas_share if sec == 1
gen contemp_any_sec = mean_any_tech*oas_share if sec == 1
gen contemp_mean_oas_sec = mean_count_tech*oas_share_oas if sec == 1
gen contemp_any_oas_sec =mean_any_tech*oas_share_oas if sec == 1


*new category: all oas workers except postal workers, supervisors, couriers, meter readers, and stock clerks
gen office = 1
replace office = 0 if (census2010 == 5000 | census2010 == 5510  | census2010 == 5530  | census2010 == 5540 | census2010 == 5550 | census2010 == 5560 | census2010 == 5850 | census2010 == 5620 )



gen contemp_mean_office = mean_count_tech*oas_share if office  == 1
gen contemp_any_office = mean_any_tech*oas_share if office == 1
gen contemp_mean_oas_office = mean_count_tech*oas_share_oas if office == 1
gen contemp_any_oas_office =mean_any_tech*oas_share_oas if office == 1


collapse  (sum) contemp_mean (sum) contemp_any (sum) contemp_mean_oas (sum) contemp_any_oas ///
(sum) contemp_office (sum) contemp_excel ///
(sum) contemp_mean_sec (sum) contemp_any_sec (sum) contemp_mean_oas_sec (sum) contemp_any_oas_sec ///
(sum) contemp_mean_office (sum) contemp_any_office (sum) contemp_mean_oas_office  (sum) contemp_any_oas_office, by (year czone) 


save "$dir/data/interim/cz_contemp_tech.dta", replace



